//
// Created by lenovo on 25-5-2.  运算符重载
//
#include "iostream"
#include <cstring>
using  namespace std;
class Person{
    friend ostream &operator<<(ostream &cout,Person &p);
public:
    int m_num1;
    int m_num2;
public:
    Person(int a,int b);
    Person();
    Person operator+(Person &p) const;//成员函数重载+运算符
    Person operator<<(Person &p) const;
    void show() const;
};
Person::Person(int a,int b) {
    m_num1 = a;
    m_num2 = b;
}
Person::Person() = default;
Person Person::operator+(Person &p) const {
    cout<<"成员函数运算符重载"<<endl;
    Person temp;
    temp.m_num1 = this->m_num1+p.m_num1;
    temp.m_num2 = this->m_num2+p.m_num2;
    return temp;
}
void Person::show() const {
    cout<<"num1: "<<m_num1<<endl;
    cout<<"num2: "<<m_num2<<endl;
}
Person Person::operator<<(Person &p) const {
    return Person();
}//todo：不使用成员函数重载左移运算符，无法实现cout在左侧
Person operator+(Person &p1,Person &p2)
{
    cout<<"全局函数运算符重载"<<endl;
    Person temp;
    temp.m_num1 = p1.m_num1+p2.m_num1;
    temp.m_num2 = p1.m_num2+p2.m_num2;
    return temp;
}//全局函数重载
Person operator+(Person &p1,int num)
{
    cout<<"函数重载版本"<<endl;
    Person temp;
    temp.m_num1 = p1.m_num1+num;
    temp.m_num2 = p1.m_num2+num;
    return temp;
}
ostream &operator<<(ostream &cout,Person &p)
{
    cout<<"m_num1:"<<p.m_num1<<"\nm_num2:"<<p.m_num2;
    return cout;
}
void Test01()
{
    Person p1(1,3);
    Person p2(3,3);
    Person p3 = p1.operator+(p2);
    p3.show();
}
void Test02()
{
    Person p1(1,3);
    Person p2(3,3);
    Person p3 = operator+(p1,p2);
    p3.show();
}
void Test03()
{
    Person p1(6,9);
    Person p2(5,7);
    Person p3;
    p3= p2+p1;
    p3.show();
}
void Test04()
{
    Person p1(6,10);
    Person p3 = p1+10;
    p3.show();
}
void Test05()
{
    Person p1(13,24);
    //cout<<p1.m_num1<<endl;
    cout<<p1<<"hello word"<<endl;
}
int main()
{
    Test05();
    return 0;
}